package com.ics.web.controller.travelstar.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ics.common.annotation.Log;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.AjaxResult;
import com.ics.common.enums.BusinessType;
import com.ics.common.utils.poi.ExcelUtil;
import com.ics.web.controller.travelstar.domain.TbVisitorsLog;
import com.ics.web.controller.travelstar.dto.VisitorsLogDTO;
import com.ics.web.controller.travelstar.service.ITbVisitorsLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * 访客记录Controller
 *
 * @author ics
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/tires/log")
public class TbVisitorsLogController extends BaseController {

    @Resource
    private ITbVisitorsLogService tbVisitorsLogService;

    /**
     * 查询访客记录列表
     */
    @ApiOperation("查询访客记录列表")
    @GetMapping("/list")
    public AjaxResult list(VisitorsLogDTO logDTO) {
        return success(tbVisitorsLogService.listPage(logDTO));
    }

    /**
     * 导出访客记录列表
     */
    @ApiOperation("导出访客记录列表")
    @Log(title = "访客记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisitorsLogDTO logDTO) {
        IPage<TbVisitorsLog> list = tbVisitorsLogService.listPage(logDTO);
        ExcelUtil<TbVisitorsLog> util = new ExcelUtil<TbVisitorsLog>(TbVisitorsLog.class);
        util.exportExcel(response, list.getRecords(), "访客记录数据");
    }

    /**
     * 获取访客记录详细信息
     */
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbVisitorsLogService.getById(id));
    }

    /**
     * 新增访客记录
     */
    @Log(title = "访客记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TbVisitorsLog tbVisitorsLog) {
        return toAjax(tbVisitorsLogService.saveOrUpdate(tbVisitorsLog));
    }


    /**
     * 删除访客记录
     */
    @Log(title = "访客记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestParam("ids") String ids) {
        return toAjax(tbVisitorsLogService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
